# -*- encoding:utf-8 -*-
'''
	pipelinesexcel.py.py
	======================
	@descript: 
	@copyright:chinasoft
	@author:guoxiaofei
	@date: 2021-01-26 17:47
	@version:v1.0
'''
# 导入excel读写模块
from openpyxl import Workbook


class Pipelineexcel(object):
    def open_spider(self, spider):
        self.wb = Workbook()
        self.ws = self.wb.active
        # 设置表头
        self.ws.append(['电视剧名称', '电视剧链接', '电视剧图片链接'])

    def process_item(self, item, spider):
        for i in range(len(item['videoname'])):
            # 把数据中每一项整理出来
            line = [item['videoname'][i], item['videourl'][i], item['videoimage'][i]]
            self.ws.append(line)  # 将数据以行的形式添加到xlsx中
        return item

    def close_spider(self, spider):
        self.wb.save('output/data.xlsx')
